package com.tanhua.server.controller;

import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 添加联系人
     * POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity addContact(@RequestBody Map map) {
        Long targetUserId = Long.parseLong(map.get("userId").toString());
        return messageService.addContact(targetUserId);
    }

    /**
     * 联系人列表
     * GET/messages/contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity contactsList(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       @RequestParam(required = false) String keyword) {
        return messageService.contactsList(page, pagesize, keyword);
    }

    /**
     * 点赞列表
     * GET/messages/likes
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        return messageService.findCommentListByType(page, pagesize, 1, 1);
    }

    /**
     * 文字评论列表
     * GET/messages/comments
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize) {
        return messageService.findCommentListByType(page, pagesize, 2, 1);
    }

    /**
     * 喜欢列表
     * GET/messages/loves
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        return messageService.findCommentListByType(page, pagesize, 3, 1);
    }


    /**
     * 公告列表
     * GET/messages/announcements
     */
    ///announcements
    //公告列表
    @GetMapping("/announcements")
    public ResponseEntity findAnnouncementList(@RequestParam(defaultValue = "1") int page,
                                               @RequestParam(defaultValue = "10") int pagesize){

        return messageService.findAnnouncementList(page,pagesize);
    }


}
